//
//  UIColor+HexToRgb.m
//  KSLMenuToolBar
//
//  Created by kensla on 14-8-13.
//  Copyright (c) 2014年 kensla. All rights reserved.
//

#import "UIColor+HexToRgb.h"

@implementation UIColor (HexToRgb)
// takes @"#123456"
+ (UIColor *)colorWithHexString:(NSString *)str inAlpha:(float)alpha {
    const char *cStr = [str cStringUsingEncoding:NSASCIIStringEncoding];
    long x = strtol(cStr+1, NULL, 16);
    return [UIColor colorWithHex:x inAlpha:alpha];
}

// takes 0x123456
+ (UIColor *)colorWithHex:(UInt32)col inAlpha:(float)alpha{
    unsigned char r, g, b;
    b = col & 0xFF;
    g = (col >> 8) & 0xFF;
    r = (col >> 16) & 0xFF;
    return [UIColor colorWithRed:(float)r/255.0f green:(float)g/255.0f blue:(float)b/255.0f alpha:alpha];
}


+ (UIColor *)colorFromCode:(int)hexCode inAlpha:(float)alpha {
    float red   = ((hexCode >> 16) & 0x000000FF)/255.0f;
    float green = ((hexCode >> 8) & 0x000000FF)/255.0f;
    float blue  = ((hexCode) & 0x000000FF)/255.0f;
    return [UIColor colorWithRed:red
                           green:green
                            blue:blue
                           alpha:alpha];
}


@end
